from Tkinter import *

class GUIApplication(Frame):
    
    
    def addController(self,controller):
        self.leapController = controller
    
    def add_one(self):
        #self.counter += 0.33
        tmpRoll = self.leapController.getRollVal()
        self.setRollPitch(tmpRoll,0)
        self.after(500, self.add_one)


    def setRollPitch(self,roll,pitch):
        self.strRotation.set("%5.2f"%roll)
        
    #just creates the labels as part of the class
    def createLabels(self):
        self.lbPitch = Label(self, text="Pitch: ")
        self.lbYaw = Label(self,text="Yaw: ")
        self.lbRotation = Label(self,text="Roll: ")
        self.lbPitchVal = Label(self, textvariable=self.strPitch, bg = "white")
        self.lbYawVal = Label(self, textvariable=self.strYaw, bg = "white")
        self.lbRotationVal = Label(self, textvariable=self.strRotation, bg = "white")
        
        self.lbGesture = Label(self, text = "Gesture: ")
        self.lbGestureVal = Label(self, textvariable = self.strGesture, bg = "white")
        
        
        
    #puts together the grid display
    def createGrid(self):
        self.lbPitch.grid(row = 0)
        self.lbPitchVal.grid(row = 0 , column = 1)
        #self.grid.SetCellBackgroundColour(0, 1, color)
        
        self.lbYaw.grid(row = 1)
        self.lbYawVal.grid(row = 1, column = 1)
        
        self.lbRotation.grid(row = 2)
        self.lbRotationVal.grid(row =2, column = 1)
        
        self.lbGesture.grid(row = 3)
        self.lbGestureVal.grid(row = 3, column = 1)
        
        
        
    #this code came with this example code.    
    def createWidgets(self):
        self.QUIT = Button(self)
        self.QUIT["text"] = "QUIT"
        self.QUIT["fg"]   = "red"
        self.QUIT["command"] =  self.quit

        self.QUIT.pack({"side": "left"})

        self.hi_there = Button(self)
        self.hi_there["text"] = "Hello",
        self.hi_there["command"] = self.say_hi

        self.hi_there.pack({"side": "left"})

    def __init__(self, master=None):
        self.counter = 0
        self.leapController = None
        #init some vars
        self.strPitch = StringVar()
        self.strPitch.set( "-99.00" )
        self.strYaw = StringVar()
        self.strYaw.set("-99.00")
        self.strRotation = StringVar()
        self.strRotation.set("-99.00")
        self.strGesture = StringVar()
        self.strGesture.set("NONE")
        
        #init the main fram
        Frame.__init__(self, master)
        
        #build the widgets
        self.pack()
        self.createLabels()
        self.createGrid()
        #self.createWidgets()
#The following are just a way to do some debugging. 
#call the class from somewhere else instead.
#root = Tk()
#app = GUIApplication(master=root)
#app.mainloop()
#root.destroy()